home *** CD-ROM | disk | FTP | other *** search
/ Holt Researcher: American History / Holt Researcher: American History.iso / pc / modules / dbtable.dxr / 00012_subtable object.ls < prev    next >
Encoding:
Text File  |  2000-01-18  |  12.9 KB  |  517 lines

  1. property _me, pTable, pSuperTable, pTableChannel, pTableLoc, pVSlider, pHSlider, pVisRect, pMinRect, pL, pT, pSpriteWidth, pSpriteHeight, pMemWidth, pMemHeight, pStageRect, pStdRowHeight, pColWidthList, pNewSpriteRect
  2. global gGraph
  3.  
  4. on new me, tableName, castName, tableChannel, tableLoc, vSlider, HSlider, descendant
  5.   if objectp(descendant) then
  6.     _me = descendant
  7.   else
  8.     _me = me
  9.   end if
  10.   pTable = member(tableName, castName)
  11.   pTableChannel = tableChannel
  12.   puppetSprite(pTableChannel, 1)
  13.   set the member of sprite pTableChannel to pTable
  14.   pTableLoc = tableLoc
  15.   pVSlider = vSlider
  16.   pHSlider = HSlider
  17.   pStdRowHeight = getRowHeight(member(pTable), 1)
  18.   pColWidthList = GetWidthList(me)
  19.   return me
  20. end
  21.  
  22. on init me, Var
  23.   pStageRect = rect(0, 0, the stageRight - the stageLeft, the stageBottom - the stageTop)
  24.   pMinRect = Var
  25.   set the rect of sprite the pTableChannel of me to pMinRect
  26.   pL = getAt(pMinRect, 1)
  27.   pT = getAt(pMinRect, 2)
  28.   if IsTableVisible(me) then
  29.     set the loc of sprite the pTableChannel of me to CalcCenterofRect(_me, pMinRect)
  30.     pSpriteWidth = the width of sprite pTableChannel
  31.     pSpriteHeight = the height of sprite pTableChannel
  32.     pMemWidth = member(pTable).width
  33.     pMemHeight = member(pTable).height
  34.   end if
  35.   return me
  36. end
  37.  
  38. on setSuperTable me, superTable
  39.   pSuperTable = superTable
  40.   return me
  41. end
  42.  
  43. on MapCharsToPlatform me
  44.   if the machineType = 256 then
  45.     dataList = member(pTable).tableData
  46.     FindText = numToChar(202)
  47.     ReplaceText = numToChar(160)
  48.     MaxCount = count(dataList)
  49.     repeat with rc = 1 to MaxCount
  50.       xText = getAt(dataList, rc)
  51.       nbsCount = CountNBSpace(xText)
  52.       TestInteger = MakeNumericOnly(xText)
  53.       if integer(TestInteger) > 10000 then
  54.         nothing()
  55.       end if
  56.       xText = FindandReplace(xText, FindText, ReplaceText)
  57.       xText = CharMaptoPC(xText)
  58.       case nbsCount of
  59.         1:
  60.           xText = AppendNbs(xText, 2)
  61.         2:
  62.           xText = AppendNbs(xText, 3)
  63.         3:
  64.           xText = AppendNbs(xText, 5)
  65.         4:
  66.           xText = AppendNbs(xText, 5)
  67.         5:
  68.           xText = AppendNbs(xText, 7)
  69.         6:
  70.           xText = AppendNbs(xText, 7)
  71.         7:
  72.           xText = AppendNbs(xText, 7)
  73.         8:
  74.           xText = AppendNbs(xText, 8)
  75.         9:
  76.           xText = AppendNbs(xText, 8)
  77.         10:
  78.           xText = AppendNbs(xText, 9)
  79.       end case
  80.       setAt(dataList, rc, xText)
  81.     end repeat
  82.     member(pTable).tableData = dataList
  83.   end if
  84.   return me
  85. end
  86.  
  87. on SetPostShowProps me
  88.   SpriteRect = the rect of sprite pTableChannel
  89.   SouthEastCell = getMouseCell(_me, getAt(SpriteRect, 3) - 2, getAt(SpriteRect, 4) - 2)
  90.   pVisRect = rect(point(1, 1), SouthEastCell)
  91.   return me
  92. end
  93.  
  94. on GetInvisibleRowCount me
  95.   RealRowHeight = pStdRowHeight - 1
  96.   MaxRow = getNumRows(me)
  97.   Settings = MaxRow - getAt(pVisRect, 4) + 1
  98.   repeat with rc = 1 to MaxRow
  99.     RowHeight = getRowHeight(member(pTable), rc)
  100.     if RowHeight > pStdRowHeight then
  101.       AddToSetting = (RowHeight / RealRowHeight) - 1
  102.       Settings = Settings + AddToSetting
  103.     end if
  104.   end repeat
  105.   return Settings
  106. end
  107.  
  108. on GetInvisibleColumnCount me
  109.   xMax = pSpriteWidth + 1
  110.   CummWidth = 0
  111.   MaxColumnCount = getNumColumns(me)
  112.   VisibleColumns = 0
  113.   if MaxColumnCount = 1 then
  114.     VisibleColumns = 2
  115.   else
  116.     PrevWidth = 0
  117.     repeat with rc = 1 to MaxColumnCount
  118.       CurrWidth = getColumnWidth(member(pTable), rc) - 1
  119.       if (PrevWidth + 10) > (CurrWidth * 2) then
  120.         VisibleColumns = VisibleColumns + 1
  121.       end if
  122.       if (CummWidth + CurrWidth) < xMax then
  123.         CummWidth = CummWidth + CurrWidth
  124.         VisibleColumns = VisibleColumns + 1
  125.       else
  126.         exit repeat
  127.       end if
  128.       PrevWidth = CurrWidth
  129.     end repeat
  130.   end if
  131.   return MaxColumnCount - VisibleColumns + 1
  132. end
  133.  
  134. on condemn me
  135.   _me = 0
  136.   return me
  137. end
  138.  
  139. on Inscope me
  140.   puppetSprite(pTableChannel, 1)
  141.   return me
  142. end
  143.  
  144. on outScope me
  145.   puppetSprite(pTableChannel, 0)
  146.   return me
  147. end
  148.  
  149. on showMe me
  150.   set the loc of sprite pTableChannel to pTableLoc
  151.   updateStage()
  152.   return me
  153. end
  154.  
  155. on hideMe me
  156.   set the loc of sprite pTableChannel to point(-9999, -9999)
  157.   updateStage()
  158.   return me
  159. end
  160.  
  161. on trackMouse me
  162.   return me
  163. end
  164.  
  165. on doRollover me
  166.   return me
  167. end
  168.  
  169. on scrollToTop me
  170.   if IsTableVisible() then
  171.     sprite(pTableChannel).vScroll = 0
  172.   end if
  173.   return me
  174. end
  175.  
  176. on scrollToLeft me
  177.   if IsTableVisible() then
  178.     sprite(pTableChannel).hScroll = 0
  179.   end if
  180.   return me
  181. end
  182.  
  183. on scrollUp me
  184.   if IsTableVisible() then
  185.     oldTop = pVisRect.top
  186.     pVisRect.top = pVisRect.top + (getSetting(pVSlider) - oldTop)
  187.     pVisRect.bottom = pVisRect.bottom + (getSetting(pVSlider) - oldTop)
  188.     sprite(pTableChannel).vScroll = (pStdRowHeight - 1) * (getSetting(pVSlider) - 1)
  189.   end if
  190.   return me
  191. end
  192.  
  193. on scrollDown me
  194.   if IsTableVisible() then
  195.     oldTop = pVisRect.top
  196.     pVisRect.top = pVisRect.top + (getSetting(pVSlider) - oldTop)
  197.     pVisRect.bottom = pVisRect.bottom + (getSetting(pVSlider) - oldTop)
  198.     sprite(pTableChannel).vScroll = (pStdRowHeight - 1) * (getSetting(pVSlider) - 1)
  199.   end if
  200.   return me
  201. end
  202.  
  203. on scrollLeft me, HScrollIncrement
  204.   if IsTableVisible() then
  205.     oldLeft = pVisRect.left
  206.     pVisRect.left = pVisRect.left + (getSetting(pHSlider) - oldLeft)
  207.     increment = CountVisibleColumns(me)
  208.     pVisRect.right = pVisRect.left + increment
  209.     if voidp(HScrollIncrement) then
  210.       sprite(pTableChannel).hScroll = (getColumnWidth(member(pTable), oldLeft) - 1) * (getSetting(pHSlider) - 1)
  211.     else
  212.       sprite(pTableChannel).hScroll = HScrollIncrement
  213.     end if
  214.   end if
  215.   return me
  216. end
  217.  
  218. on scrollRight me, HScrollIncrement
  219.   if IsTableVisible() then
  220.     if voidp(HScrollIncrement) then
  221.       oldLeft = pVisRect.left
  222.       pVisRect.left = pVisRect.left + (getSetting(pHSlider) - oldLeft)
  223.       increment = CountVisibleColumns(me)
  224.       pVisRect.right = pVisRect.left + increment
  225.       sprite(pTableChannel).hScroll = (getColumnWidth(member(pTable), oldLeft) - 1) * (getSetting(pHSlider) - 1)
  226.     else
  227.       if maxReached(pHSlider) then
  228.         pVisRect.left = CountColumnsMaxReached(me)
  229.         pVisRect.right = getNumColumns(me)
  230.       else
  231.         Adder = CountColumnsInWidth(me, HScrollIncrement)
  232.         pVisRect.left = pVisRect.left + Adder
  233.         pVisRect.right = pVisRect.right + Adder
  234.       end if
  235.       sprite(pTableChannel).hScroll = HScrollIncrement
  236.     end if
  237.   end if
  238.   return me
  239. end
  240.  
  241. on CountVisibleColumns me
  242.   CummWidth = 0
  243.   MaxCount = count(pColWidthList)
  244.   setting = pVisRect.left
  245.   columnCount = 0
  246.   repeat with rc = setting to MaxCount
  247.     Test = CummWidth + getAt(pColWidthList, rc)
  248.     if Test < pSpriteWidth then
  249.       CummWidth = Test
  250.       columnCount = columnCount + 1
  251.     end if
  252.   end repeat
  253.   if columnCount = 1 then
  254.     columnCount = 0
  255.   end if
  256.   return columnCount
  257. end
  258.  
  259. on CountColumnsMaxReached me
  260.   CummWidth = 0
  261.   MaxCount = count(pColWidthList)
  262.   repeat with rc = MaxCount down to 1
  263.     Test = CummWidth + getAt(pColWidthList, rc)
  264.     if Test < pSpriteWidth then
  265.       CummWidth = Test
  266.       next repeat
  267.     end if
  268.     exit repeat
  269.   end repeat
  270.   return rc
  271. end
  272.  
  273. on CountColumnsInWidth me, width
  274.   start = pVisRect.left
  275.   MaxCount = count(pColWidthList)
  276.   CummWidth = 0
  277.   repeat with rc = start to MaxCount
  278.     Test = CummWidth + getAt(pColWidthList, rc)
  279.     if Test < width then
  280.       CummWidth = Test
  281.       next repeat
  282.     end if
  283.     if rc = 1 then
  284.       ReturnVar = rc
  285.     else
  286.       ReturnVar = rc - start
  287.     end if
  288.     exit repeat
  289.   end repeat
  290.   if voidp(ReturnVar) then
  291.     ReturnVar = rc - start - 1
  292.   end if
  293.   return ReturnVar
  294. end
  295.  
  296. on JustifyText me, WhichSide
  297.   member(pTable).defaultHAlign = WhichSide
  298. end
  299.  
  300. on getTopRow me
  301.   return pVisRect.top
  302. end
  303.  
  304. on getLeftColumn me
  305.   return pVisRect.left
  306. end
  307.  
  308. on atTop me
  309.   return pVisRect.top = 1
  310. end
  311.  
  312. on atBottom me
  313.   return pVisRect.bottom = pTable.rowCount
  314. end
  315.  
  316. on atLeft me
  317.   return pVisRect.left = 1
  318. end
  319.  
  320. on atRight me
  321.   return pVisRect.right = pTable.columnCount
  322. end
  323.  
  324. on isLeftOf me, h
  325.   return h <= the left of sprite pTableChannel
  326. end
  327.  
  328. on isRightOf me, h
  329.   return h > the right of sprite pTableChannel
  330. end
  331.  
  332. on getMouseCell me, h, v
  333.   if v <= the top of sprite pTableChannel then
  334.     v = the top of sprite pTableChannel + 1
  335.   else
  336.     if v > the bottom of sprite pTableChannel then
  337.       v = the bottom of sprite pTableChannel - 1
  338.     end if
  339.   end if
  340.   if h <= the left of sprite pTableChannel then
  341.     h = the left of sprite pTableChannel + 1
  342.   else
  343.     if h > the right of sprite pTableChannel then
  344.       h = the right of sprite pTableChannel - 1
  345.     end if
  346.   end if
  347.   return cellToPoint(me._me, pointToCell(sprite(pTableChannel), point(h, v)))
  348. end
  349.  
  350. on getVisRect me, theRect
  351.   R = rect(0, 0, 0, 0)
  352.   if not ((theRect.left > pVisRect.right) or (theRect.top > pVisRect.bottom) or (theRect.right < pVisRect.left) or (theRect.bottom < pVisRect.top)) then
  353.     R.left = max(theRect.left, pVisRect.left)
  354.     R.top = max(theRect.top, pVisRect.top)
  355.     R.right = min(theRect.right, pVisRect.right)
  356.     R.bottom = min(theRect.bottom, pVisRect.bottom)
  357.   end if
  358.   if R <> rect(0, 0, 0, 0) then
  359.     r1 = getCellRect(sprite(pTableChannel), point(getAt(R, 1), getAt(R, 2)))
  360.     r2 = getCellRect(sprite(pTableChannel), point(getAt(R, 3), getAt(R, 4)))
  361.     if voidp(r1) or voidp(r2) then
  362.       R = rect(0, 0, 0, 0)
  363.     else
  364.       R = rect(r1.left, r1.top, r2.right, r2.bottom)
  365.     end if
  366.   end if
  367.   return R
  368. end
  369.  
  370. on cellToPoint me, theCell
  371.   if (theCell mod pTable.columnCount) = 0 then
  372.     return point(pTable.columnCount, theCell / pTable.columnCount)
  373.   else
  374.     return point(theCell mod pTable.columnCount, (theCell / pTable.columnCount) + 1)
  375.   end if
  376. end
  377.  
  378. on getCellRect me, theCell
  379.   return getCellRect(sprite(pTableChannel), theCell)
  380. end
  381.  
  382. on isCellVisible me, theCellRect
  383.   return intersect(the rect of sprite pTableChannel, theCellRect) <> rect(0, 0, 0, 0)
  384. end
  385.  
  386. on GetMaxVisibleXPixel me, xMax
  387.   CummWidth = pL + 1
  388.   MaxColumnCount = getNumColumns(me)
  389.   if MaxColumnCount = 1 then
  390.     CummWidth = CummWidth + getColumnWidth(member(pTable), 1)
  391.   else
  392.     repeat with rc = 1 to MaxColumnCount
  393.       CurrWidth = getColumnWidth(member(pTable), rc) - 1
  394.       if (CummWidth + CurrWidth) < xMax then
  395.         CummWidth = CummWidth + CurrWidth
  396.         next repeat
  397.       end if
  398.       exit repeat
  399.     end repeat
  400.   end if
  401.   return CummWidth
  402. end
  403.  
  404. on GetMaxVisibleYPixel me, yMax
  405.   CummHeight = pT
  406.   MaxRowCount = getNumRows(me)
  407.   repeat with rc = 1 to MaxRowCount
  408.     CurrHeight = getRowHeight(member(pTable), rc) - 1
  409.     if (CummHeight + CurrHeight) < yMax then
  410.       CummHeight = CummHeight + CurrHeight
  411.       next repeat
  412.     end if
  413.     exit repeat
  414.   end repeat
  415.   return CummHeight
  416. end
  417.  
  418. on SetTableMin me
  419.   if IsTableVisible() then
  420.     pNewSpriteRect = pMinRect
  421.     set the rect of sprite pTableChannel to pMinRect
  422.     set the loc of sprite pTableChannel to CalcCenterofRect(_me, pNewSpriteRect)
  423.     pSpriteWidth = the width of sprite pTableChannel
  424.     pSpriteHeight = the height of sprite pTableChannel
  425.   end if
  426. end
  427.  
  428. on SetTableMax me, xMax, yMax
  429.   if IsTableVisible() then
  430.     if not voidp(xMax) then
  431.       SetWidth(me, xMax)
  432.       pSpriteWidth = the width of sprite pTableChannel
  433.     end if
  434.     if not voidp(yMax) then
  435.       SetHeight(me, yMax)
  436.       pSpriteHeight = the height of sprite pTableChannel
  437.     end if
  438.     pNewSpriteRect = rect(pL, pT, pL + the width of sprite pTableChannel, pT + the height of sprite pTableChannel)
  439.     if not voidp(xMax) or not voidp(yMax) then
  440.       set the loc of sprite pTableChannel to CalcCenterofRect(_me, pNewSpriteRect)
  441.     end if
  442.   end if
  443. end
  444.  
  445. on SetWidth me, xMax
  446.   if (pL + pMemWidth) < xMax then
  447.     set the width of sprite pTableChannel to pMemWidth
  448.   else
  449.     set the width of sprite pTableChannel to xMax - pL
  450.   end if
  451. end
  452.  
  453. on SetHeight me, yMax
  454.   if (pT + pMemHeight) < yMax then
  455.     set the height of sprite pTableChannel to pMemHeight
  456.   else
  457.     set the height of sprite pTableChannel to yMax - pT
  458.   end if
  459. end
  460.  
  461. on getSelectedData me, theRect
  462.   offset = 17
  463.   fMember = the number of member pTable + offset
  464.   data = value(the text of field fMember)
  465.   selectedData = []
  466.   repeat with i = theRect.top to theRect.bottom
  467.     repeat with j = theRect.left to theRect.right
  468.       append(selectedData, getAt(data, ((i - 1) * pTable.columnCount) + j))
  469.     end repeat
  470.   end repeat
  471.   MaxCount = count(selectedData)
  472.   repeat with rc = 1 to MaxCount
  473.     xText = getAt(selectedData, rc)
  474.     xText = FindandReplace(xText, RETURN, " ")
  475.     xText = RemoveBorderSpaces(xText)
  476.     setAt(selectedData, rc, xText)
  477.   end repeat
  478.   return selectedData
  479. end
  480.  
  481. on GetNewRect me
  482.   return rect(pL, pT, pL + the width of sprite pTableChannel, pT + the height of sprite pTableChannel)
  483. end
  484.  
  485. on GetWidthList me
  486.   xList = []
  487.   MaxCol = getNumColumns(me)
  488.   repeat with xCol = 1 to MaxCol
  489.     append(xList, getColumnWidth(pTable, xCol) - 1)
  490.   end repeat
  491.   return xList
  492. end
  493.  
  494. on getNumColumns me
  495.   return pTable.columnCount
  496. end
  497.  
  498. on getNumRows me
  499.   return pTable.rowCount
  500. end
  501.  
  502. on isAbove me, v
  503.   return v <= the top of sprite pTableChannel
  504. end
  505.  
  506. on isBelow me, v
  507.   return v > the bottom of sprite pTableChannel
  508. end
  509.  
  510. on IsTableVisible me
  511.   return inside(point(pL, pT), pStageRect)
  512. end
  513.  
  514. on buttonLoc me
  515.   return me
  516. end
  517.